<!DOCTYPE html>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<html>
<head>
<title>${name_china}管理列表</title>
<%@include file="/common/head.jsp" %>
<style>
.top-area{
	 height:100px;
	 width:100%;
	 display:flex;
	 flex-direction: row;
	 margin-top:30px;
}
.top-item{
	height:80px;
	width:25%;
	font-size:20px;
}
</style>
</head>
<body class="iframe-page">
<div class="page-title-wrapper">
    <div class="page-title">
        <div class="page-title-text">
            <span>${name_china}管理</span>
        </div>
        <a id="goBack" class="btn-return distance-left" href="javascript:;"><i class="icon icon-arrow-left"></i>返回上级</a>
        <div id="toolbar" style="float: right"></div>
    </div>
    <div class="page-title-border"></div>
</div>
<div class="top-area">
	<div class="top-item">销售额：${totalSale}</div>
	<div class="top-item">利润额：${totalProfit}</div>
	<div class="top-item">店铺：${totalStore}</div>
	<div class="top-item">订单量：${totalOrder}</div>
</div>
<div class="search-field">
    <span class="field-cont">
        <span class="field-cont-title">店铺名称/城市合伙人/业务员</span>
        <input type="text" class="summer-input" id="partnerName"/>
    </span>
    
     <span class="field-cont">
        <span class="field-cont-title">销售额>=</span>
        <input type="text" class="summer-input" id="totalInMoneySlef"/>
    </span>
    
    <span class="field-cont">
        <span class="field-cont-title">订单量>=</span>
        <input type="text" class="summer-input" id="totalOrders"/>
    </span>
    
    <span class="field-cont">
        <span class="field-cont-title">销售利润>=</span>
        <input type="text" class="summer-input" id="totalProfit"/>
    </span>
    
    <span class="field-btn-wrapper">
        <a id="search" class="btn btn-primary btn-icon wave distance-right"><i class="icon icon-search"></i></a>
        <a id="reset" class="btn btn-icon wave wave-dark"><i class="icon icon-refresh"></i></a>
    </span>
</div>

<div id="t-wrap">
    <table class="summer-datagrid" id="dataList">
	    <thead>
		    <tr>
		        <th>店铺名称</th>
		        <th>图片</th>
		        <th>店铺地址</th>
				<th>城市合伙人</th>
				<th>业务员</th>
				<th>销售额</th>
				<th>订单量</th>
				<th>销售利润</th>
		        <th>操作</th>
		    </tr>
	    </thead>
    </table>
</div>

<script>
	//请求url
	var CONST_URL = {
		STORE_LIST: basePath + '${common_url}storeList',
		INIT_CITY_CHECK: basePath + '${common_url}initCityCheck',
		INIT_CITY_STORE_DETAIL: basePath + '${common_url}initCityStoreDetail',
		INIT_VIEW: basePath + '${common_url}initView'
	};
	
    var  cityId,
    	 pId,
    	 permission = CommonUtil.getPermission('${name_english}');
    
    $(function () {
    	console.log(permission);
    	cityId = ${cityId};
    	pId = ${pId};
    	//初始化下拉选项
    	$('#identity').combobox({
            valueField : 'code',
            textField : 'name',
            url : COMMON_URL.getCode + '?type=T_DM_PARTNER_APPLY_TYPE'
        });
        //城市合伙人-店铺订单详情
        $('#t-wrap').on('click', 'a[data-permit="${name_english}:initCityStoreDetail"]', function() {
            var $this = $(this),
            id = $this.closest('tr').find('td[data-field="id"]').attr('data-value');
            window.location.href = CONST_URL.INIT_CITY_STORE_DETAIL + '?id=' + id+"&saleId="+pId+"&cityId="+cityId;
        });
      //initView
        $('#t-wrap').on('click', 'a[data-permit="${name_english}:initView"]', function() {
            var $this = $(this),
            id = $this.closest('tr').find('td[data-field="id"]').attr('data-value');
            window.location.href = CONST_URL.INIT_VIEW + '?id=' + id;
        });
        // 查询按钮
        $('#search').on('click', reloadTable);
      	//返回按钮
   		$('#backBtn, #goBack').on('click',backMain);
        //重置按钮
        $('#reset').on('click', function () {
        	//重置文本框的值
        	$('#partnerName').val('');
        	$('#totalInMoneySlef').val('');
        	$('#totalOrders').val('');
        	$('#totalProfit').val('');
        	reloadTable();
        });
        
       createTable();
        
    });
  	//返回主页面
    function backMain() {
    	window.location.href = CONST_URL.INIT_MAIN;
    }
    // 重新加载表格
	function reloadTable() {
		$('#dataList').datagrid('reload',{
            ajax: {
            	param: {
            		"partnerName": trimSpace($('#partnerName').val()),
            		"totalInMoneySlef": trimSpace($('#totalInMoneySlef').val()),
            		"totalOrders": trimSpace($('#totalOrders').val()),
            		"totalProfit": trimSpace($('#totalProfit').val()),
            		"pId": pId
            	}
            }
        });
	}
    
    //创建表格
    function createTable() {
    	$('#dataList').datagrid({
    		ajax: {
    			url: CONST_URL.STORE_LIST,
    			param: {
    				"partnerName": trimSpace($('#partnerName').val()),
            		"totalInMoneySlef": trimSpace($('#totalInMoneySlef').val()),
            		"totalOrders": trimSpace($('#totalOrders').val()),
            		"totalProfit": trimSpace($('#totalProfit').val()),
            		"pId": pId
            	}
    		},
    		columns: [
    		     {
    		    	 field: 'id',
    		    	 hidden: true
    		     },
    		     {
    		    	field: 'userId',
    		    	hidden: true
    		     },
    		     {
    		    	 field: 'partnerName'
    		     },
    		     {
    		    	 field: 'partnerImages'
    		     },
    		     {
    		    	 field: 'address'
    		     },
    		     {
    		    	field: 'cityPartner',
    		    	render:function(rowData){
    		    		var html = rowData.cityPartner +"（"+rowData.cityNo+"）";
    		    		return html;
    		    	}
    		     },
    		     {
    		    	 field: 'salePartner',
    		    	 render:function(rowData){
    		    		 var html = rowData.salePartner + "（"+rowData.saleNo+"）";
    		    		 return html;
    		    	 }
    		     },
    		     {
    		    	field:'totalInMoneySlef' 
    		     },
    		     {
    		    	 field:'totalOrders'
    		     },
    		     {
    		    	 field:'totalProfitSlef'
    		     },
    		    {
    		    	 render: function (rowData) {
    		    		 return $.funcbar({
    		    			 data: permission,    //请求的数据
    		    			 type: 'text',     //类型
    		    			 display: 1,    //显示数量
    		    			 permit: ['${name_english}:initCityStoreDetail'] //需要的权限按钮
    		    		 });
    		    	 }
    		    }
    		          
    	    ]
    	});
    }
  //返回主页面
    function backMain() {
    	window.location.href = CONST_URL.INIT_CITY_CHECK +"?id="+cityId;
    }
</script>
</body>
</html>